//
//  PersonAccountViewController.m
//  Fangmm
//
//  Created by ChaoZhou on 16/3/5.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "PersonAccountViewController.h"
#import "HttpServer.h"
#import "Utility.h"
#import "Constants.h"
#import "SettingPassWordViewController.h"
#import "AmountSettingViewController.h"
#import <UIImageView+WebCache.h>
#import "User.h"
#import "WebViewController.h"
#import <MobClick.h>



@interface PersonAccountViewController ()
@end

@implementation PersonAccountViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
    [MobClick beginLogPageView:@"个人账户页"];
    [HttpServer getAccountMssageWithSuccessBlock:^(NSDictionary *responseData)
     {
         NSLog(@"%@",responseData);
         NSDictionary *dic = responseData[@"account"];
         [Utility setObject:[NSString stringWithFormat:@"%d",[dic[@"balance"] intValue]/100] key:kBalance];
         [Utility setObject:[NSString stringWithFormat:@"%d",[dic[@"trusteeFee"] intValue]/100] key:kTrusteeFee];
         self.balanceLabel.text = [NSString stringWithFormat:@"¥ %d元",[[Utility getObjectForKey:kBalance] intValue] -  [[Utility getObjectForKey:kTrusteeFee] intValue]];
         self.entrustLabel.text = [NSString stringWithFormat:@"¥ %@元",[Utility getObjectForKey:kTrusteeFee] ];
         [self.headerImage sd_setImageWithURL:[NSURL URLWithString:((User*)[Utility getObjectForKey:kUser]).avatar] placeholderImage:[UIImage imageNamed:@"houseown"]];
         self.nickName.text = ((User*)[Utility getObjectForKey:kUser]).name;
     }
     withFailBlock:^(id errorMsg)
     {
         NSLog(@"%@",errorMsg);
     }];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [MobClick endLogPageView:@"个人账户页"];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)rechargeButton:(id)sender
{
    AmountSettingViewController *amountSettingVC = [[AmountSettingViewController alloc]init];
    amountSettingVC.type = @"encharge";
    [self.navigationController pushViewController:amountSettingVC animated:YES];
}

- (IBAction)withDrawCashButton:(id)sender
{
    AmountSettingViewController *amountSettingVC = [[AmountSettingViewController alloc]init];
    amountSettingVC.type = @"drawCash";
    amountSettingVC.completeButtonView.titleLabel.text = @"确认提现";
    [self.navigationController pushViewController:amountSettingVC animated:YES];
}


- (IBAction)paySettingButton:(id)sender
{
    
}

- (IBAction)goBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
